<template>
  <transition name="t">
    <div class="toast" :class="toastPostion" v-if="show">
      <div class="text" v-html="content"></div>
    </div>
  </transition>
</template>

<script>
export default {
  name: 'toast',
  props: {
    content: {
      type: String,
      default: ''
    },
    position: {
      type: String,
      default: 'bottom'
    },
    duration: {
      type: Number,
      default: 3000
    }
  },
  computed: {
    toastPostion () {
      return this.position === 'top' ? 'toast-top' : this.position === 'center' ? 'toast-center' : 'toast-bottom'
    }
  },
  data () {
    return {
      show: false
    }
  }
}
</script>

<style lang="less" scoped>
  @import '~common/css/variable';
  .toast {
    position: fixed;
    background-color: rgba(0,0,0,0.4);
    padding: 5px 8px;
    max-width: 80px;
    left: 50%;
    transform: translate3d(-50%,0,0);
    border-radius: 3px;
    z-index: 999;
    .text {
      color: white;
      font-size: @font-size-small;
      text-align: center;
    }
  }
  .toast-top{
    top: 10%;
  }
  .toast-center {
    top: 40%;
  }
  .toast-bottom {
    top: 80%;
  }
  .t-enter, .t-leave-to {
    opacity: 0;
  }
  .t-enter-active, .t-leave-active {
    transition: all .3s;
  }
</style>
